#!/usr/bin/perl

my $words = $ARGV[0];

my $n = 0;
while ( <STDIN> ) {
	# Check whether we have reached max number of words
	last() if ($n > $words);

	# Save words
	print $_;
	$n += scalar(split(/\s+/, $_));
	print STDERR $n . "\n";
}


